<template>
  <div class="comment-reply">
    <van-nav-bar
      :title="
        comment.reply_count > 0 ? `${comment.reply_count}条回复` : '暂无回复'
      "
    >
      <template #left>
        <van-icon name="cross" @click="$emit('close')" />
      </template>
    </van-nav-bar>

    <div class="scroll-wrap">
      <!-- 选中的评论 -->
      <comment-item :comment="comment"></comment-item>

      <!-- 评论回复列表 -->
      <van-cell title="全部回复"></van-cell>
      <comment-list
        type="c"
        :source="comment.com_id"
        :list="CommentListss"
      ></comment-list>
    </div>

    <div class="post-wrap">
      <van-button
        class="post-btn"
        size="small"
        round
        @click="isReplyShow = true"
        >写评论</van-button
      >
    </div>

    <!-- 发布评论回复 -->
    <van-popup v-model="isReplyShow" position="bottom" style="height: 20%;">
      <comment-post
        :target="comment.com_id"
        @post-success="onPostSuccess"
        addComment="c"
      ></comment-post>
    </van-popup>
    <!-- /发布评论回复 -->
  </div>
</template>

<script>
import CommentItem from '@/components/CommentItem.vue';
import CommentList from '@/components/CommentList.vue';
import CommentPost from '@/components/CommentPost.vue';
export default {
  name: 'CommentReply',
  components: { CommentItem, CommentList, CommentPost },

  data() {
    return {
      isReplyShow: false,
      CommentListss: [],
    };
  },
  props: {
    comment: {
      type: Object,
      required: true,
    },
  },
  methods: {
    onPostSuccess(data) {
      this.isReplyShow = false;
      this.comment.reply_count++;
      this.CommentListss.unshift(data.new_obj);
    },
  },
};
</script>

<style lang="less" scoped>
.scroll-wrap {
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 88px;
  overflow-y: auto;
}
.post-wrap {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  border-top: 1px solid #d8d8d8;
  .post-btn {
    width: 60%;
  }
}
</style>
